const app = getApp();
import Api from '@/services/api.js'
export default {
  data() {
    return {
      list: [],
      inviteId: '',  // 分享进来的邀请id
    }
  },
  computed: {
    privacyData() {
      return this.$store.state.privacyData;
    }
  },
  onLoad(options) {
    this.inviteId = options.inviteId;
    if (this.privacyData.openId) {
      this.init()
    }else {
      app.globalData.callBack = () => {
        this.init();
      }
    }
  },
  onShareAppMessage() {
    return {
      title: '人才匹配度测评工具',
      path: 'pages/solution/index?inviteId=' + this.privacyData.userId,
      imageUrl: 'https://talentsupload.oss-cn-beijing.aliyuncs.com/miniprogram/default_2.png'
    }
  },
  methods: {
    async init() {
      if (this.inviteId) {
        await this.$Serv.userBindByInviterId({ inviterId: this.inviteId })
      }
      await this.getContentByTypeId();
    },
    tapItem(item) {
      uni.navigateTo({
        url: '../common/description/index?content=' + encodeURIComponent(JSON.stringify(item))
      })
    },
    async getContentByTypeId() {
      const {
        code,
        result
      } = await this.$request({
        url: Api.getHomeContentsByRoleId,
        data: {
          contentType: "solution",
          pageNo: 1,
          pageSize: 50,
        }
      });
      if (code === 200) {
        this.list = result.records;
      }
    },
  }
}